<?php
/**
 * 通用函数集
 *
 * @author		黑冰 <954650386@qq.com>
 */

namespace waf\modules;

use \waf\Waf;
use \waf\log\WLog;

class WCFunc
{
    /**
     * 获取本机ip
     *
     * @param string $network_seq  // 网卡序号，默认获取第一个网卡
     * @return string
     */
    public static function getLocalIp($network_seq = '')
    {
        $ret = '';

        $arrIp  = swoole_get_local_ip();
        if($arrIp && is_array($arrIp))
        {
            foreach($arrIp as $k => $ip)
            {
                if($network_seq && $network_seq == $k)
                {
                    $ret = $ip;
                    break;
                }else{
                    $ret = $ip;
                    break;
                }
            }
        }else{
            $ret = 'unknow';
        }

        return $ret;
    }

    /**
     * 获取当前时间戳的毫秒数
     *
     * @return float
     */
    public static function getCurrentMsectime()
    {
        list($msec, $sec) = explode(' ', microtime());
        $msectime =  (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
        return $msectime;
    }
}
?>
